/**
 * Created by PhpStorm.
 * User: 苦逼的小新
 * Date: 2017/4/7
 * Time: 12:49
 */
var canvas, stage,stats,musicContainer,tranContainer,clearTimer,canvas2;;
var initWidth = 750;
var initHeight = 1333;
var doFresh = function () {};
var doNextPage= function () {};
var doLastPage= function () {};
var doMyPage= function () {};
var playBGM = function () {};

window.onload=function(){

  canvas = document.createElement('canvas');
  canvas.width = initWidth;
  canvas.height = initHeight;
  canvas.style.backgroundColor="#000";
  canvas.style.position="absolute";

  document.body.appendChild(canvas);
  loading();
}


function loading(){
  stage = new createjs.Stage(canvas);
  createjs.Touch.enable(stage);
  stage.autoClear = true;
  resize();resize();
  window.onresize = function(){
    resize();
  };
  main.loading();
}

var main = {
  doSlide : false,
  data:{
    thisFPS:0,
    touchX:0,
    touchY:0,
    thisPage:0,
    endPage:7,
    slideSpeed:600,
    musicPlay:false
  },
  obj:{
    queue : new createjs.LoadQueue(),
    loadContainer:null,
    page1Container:null,
    page2Container:null,
    page3Container:null,
    page4Container:null,
    page5Container:null,
    page6Container:null,
    page7Container:null,
    page8Container:null,

  },
  loading:function(){

    main.obj.loadContainer = new createjs.Container().set({x:0,y:0});
    stage.addChild(main.obj.loadContainer);

    var shape_bg = new createjs.Shape();
    shape_bg.graphics.beginFill("#000").drawRect(0, 0, initWidth, initHeight);
    main.obj.loadContainer.addChild(shape_bg);

    var text = new createjs.Text("正在努力加载中...", "20px Arial", "#fff");
    text.x = (initWidth-text.text.length*22)/2;
    text.x = 260;
    text.y = initHeight-85;
    main.obj.loadContainer.addChild(text);
    stage.update();
    this.obj.queue.installPlugin(createjs.Sound);
    this.obj.queue.on("fileload", handleFileLoad, this);
    this.obj.queue.on("complete", handleComplete, this);
    this.obj.queue.loadManifest([
      {id:"p_love",src:"img/p_love.png"},
      {id:"p_up",src:"img/p_up.png"},
      {id:"p_ren",src:"img/p_ren.png"},
      {id:"p_xin",src:"img/p_xin.png"},
      {id:"p_jian",src:"img/p_jian.png"},
      {id:"p_xinsui",src:"img/p_xinsui.png"},
      {id:"p_shan",src:"img/p_shan.png"},
      {id:"p5_love",src:"img/p5_love.png"},

      {id:"p4_img",src:"img/p4_img.png"},

      {id:"p1_bg",src:"img/p1_bg.jpg?v=1"},
      {id:"p2_bg",src:"img/p2_bg.jpg?v=1"},
      {id:"p3_bg",src:"img/p3_bg.jpg"},
      {id:"p4_bg",src:"img/p4_bg.png"},
      {id:"p5_bg",src:"img/p5_bg.jpg"},
      {id:"p6_bg",src:"img/p6_bg.jpg?v=11"},
      {id:"p7_1",src:"img/p7_1.jpg?v=11"},
      {id:"p7_2",src:"img/p7_2.jpg?v=11"},
      {id:"p7_3",src:"img/p7_3.jpg?v=11"},
      {id:"p7_4",src:"img/p7_4.jpg?v=11"},
      {id:"p7_5",src:"img/p7_5.jpg?v=11"},
      {id:"p7_6",src:"img/p7_6.jpg?v=11"},
      {id:"p7_7",src:"img/p7_7.jpg?v=11"},
      {id:"p7_8",src:"img/p7_8.jpg?v=11"},

      {id:"p1_img",src:"img/p1_img.png?v=1"},
      {id:"p2_img",src:"img/p2_img.png"},
      {id:"p3_bgt",src:"img/p3_bgt.png"},
      {id:"p3_wdj",src:"img/p3_wdj.png"},
      {id:"p3_wdjr",src:"img/p3_wdjr.jpg"},
      {id:"p3_img1",src:"img/p3_img1.png"},
      {id:"p3_feiji",src:"img/p3_feiji.png"},
      {id:"p3_img2",src:"img/p3_img2.png"},
      {id:"p3_img3",src:"img/p3_img3.png"},
      {id:"p3_img4",src:"img/p3_img4.png"},
      {id:"p4_txt",src:"img/p4_txt.png?v=1"},
      {id:"p5_img",src:"img/p5_img.png?v=11"},
      {id:"p5_imgs",src:"img/p5_imgs.png?v=1"},
      {id:"p6_img",src:"img/p6_img.png?v=11"},
      {id:"p7_img",src:"img/p7_img.png"},
      {id:"p_btn",src:"img/p_btn.png"},


      {id:"up",src:"img/up.png"}
    ]);
    this.obj.queue.loadFile({id:"v_bgm", src:"mp3/bgm.mp3?v=11"});
    this.obj.queue.loadFile({id:"didi", src:"mp3/didi.mp3?v=11"});
    this.obj.queue.loadFile({id:"sound1", src:"mp3/sound1.mp3?v=1"});
    this.obj.queue.loadFile({id:"sound2", src:"mp3/sound2.mp3?v=1"});
    this.obj.queue.loadFile({id:"sound3", src:"mp3/sound3.mp3?v=1"});
    this.obj.queue.loadFile({id:"sound4", src:"mp3/sound4.mp3?v=1"});
    this.obj.queue.loadFile({id:"sound5", src:"mp3/sound5.mp3?v=1"});
    this.obj.queue.loadFile({id:"sound6", src:"mp3/sound6.mp3?v=1"});
    this.obj.queue.loadFile({id:"sound7", src:"mp3/sound7.mp3?v=1"});
    this.obj.queue.loadFile({id:"ILoveYou", src:"mp3/ILoveYou.mp3?v=1"});
    function handleFileLoad(evt) {
      text.text = "正在努力加载中...("+Math.floor((evt.currentTarget._numItemsLoaded/evt.currentTarget._numItems)*100)+"%)";
      if(evt.currentTarget._numItemsLoaded==2){
        var p_up= main.getAni("p_up",8,250,200,0.3);
        p_up.set({x:580,y:initHeight});p_up.gotoAndPlay("run");
        main.obj.loadContainer.addChild(p_up);
        createjs.Tween.get(p_up,{loop:true}).to({x:-200,y:100},3000);

        var p_love = main.getAni("p_love",8,250,120,0.3);
        p_love.set({x:140,y:initHeight});p_love.gotoAndPlay("run");
        main.obj.loadContainer.addChild(p_love);
        createjs.Tween.get(p_love,{loop:true}).to({x:551,y:-120},5000);

      }
    }
    function handleComplete(evt) {
      stage.removeChild(main.obj.loadContainer);
      playBGM = function () {
        createjs.Sound.play("v_bgm", {interrupt: createjs.Sound.INTERRUPT_NONE,  loop: -1, volume: 0.2});
      };

      getShareInfo();

      main.page1();
      stage.addChild(main.obj.loadContainer);
      createjs.Tween.get(main.obj.loadContainer)
        .wait(300)
        .to({alpha:0},600)
        .call(function () {
          stage.removeChild(main.obj.loadContainer);
        });
      main.data.thisPage = 1;
      stage.update();
    }
    createjs.Ticker.setFPS(60);
    createjs.Ticker.addEventListener("tick", stage);
    createjs.Ticker.addEventListener("tick", animate);
    function animate() {
      doFresh();
    }

    stage.addEventListener("mousedown",function(e){
      main.data.touchX = e.stageX;
      main.data.touchY = e.stageY;
    });
    stage.addEventListener("pressup",function(e) {
      if (Math.abs(e.stageY - main.data.touchY) < 50) {
        return;
      }
      if(main.doSlide){
        main.doSlide = false;
        setTimeout(function () {main.doSlide = true;},main.data.slideSpeed);
      }else{
        return;
      }
      if (e.stageY - main.data.touchY > 0) {
        console.log("last");
        if(main.data.thisPage==1) return;
        doLastPage(main.data.thisPage,1);
      }else {
        console.log("next");
        if(main.data.thisPage==main.data.endPage) return;
        doNextPage(main.data.thisPage,1);
      }
    });

    doNextPage = function (pageId,type) {
      console.log("doNextPage");
      initPage(pageId+1);
      var nowPage = getPage(pageId);
      stage.addChild(nowPage);
      var nextPage = getPage(pageId+1);
      if(type==1){
        createjs.Tween.get(nowPage)
          .to({y:-initHeight},main.data.slideSpeed)
          .call(function () {
            stage.removeChild(nowPage);
          });
        createjs.Tween.get(nextPage)
          .to({y:initHeight})
          .to({y:0},main.data.slideSpeed);
      }else{
        createjs.Tween.get(nowPage)
          .to({alpha:0},main.data.slideSpeed)
          .call(function () {
            stage.removeChild(nowPage);
          });
        createjs.Tween.get(nextPage)
          .to({alpha:1},main.data.slideSpeed);
      }
      main.data.thisPage++;
    };
    doLastPage = function (pageId,type) {
      initPage(pageId-1);
      var nowPage = getPage(pageId);
      stage.addChild(nowPage);
      var nextPage = getPage(pageId-1);
      if(type==1){
        createjs.Tween.get(nowPage)
          .to({y:initHeight},main.data.slideSpeed)
          .call(function () {
            stage.removeChild(nowPage);
          });
        createjs.Tween.get(nextPage)
          .to({y:-initHeight})
          .to({y:0},main.data.slideSpeed);
      }else{
        createjs.Tween.get(nowPage)
          .to({alpha:0},main.data.slideSpeed)
          .call(function () {
            stage.removeChild(nowPage);
          });
        createjs.Tween.get(nextPage)
          .to({alpha:1},main.data.slideSpeed);
      }
      main.data.thisPage--;
    };
    doMyPage = function (pageId,type) {
      initPage(pageId);
      var nowPage = getPage(main.data.thisPage);
      stage.addChild(nowPage);
      var nextPage = getPage(pageId);
      if(type==1){
        createjs.Tween.get(nowPage)
          .to({y:-initHeight},main.data.slideSpeed)
          .call(function () {
            stage.removeChild(nowPage);
          });
        createjs.Tween.get(nextPage)
          .to({y:initHeight})
          .to({y:0},main.data.slideSpeed);
      }else{
        createjs.Tween.get(nowPage)
          .to({alpha:0},main.data.slideSpeed)
          .call(function () {
            stage.removeChild(nowPage);
          });
        createjs.Tween.get(nextPage)
          .to({alpha:1},main.data.slideSpeed);
      }
      main.data.thisPage=pageId;
      console.log(main.data.thisPage);
    };

    function initPage(id) {
      switch (id){
        case 1:
          main.page1();
          break;
        case 2:
          main.page2();
          break;
        case 3:
          main.page3();
          break;
        case 4:
          main.page4();
          break;
        case 5:
          main.page5();
          break;
        case 6:
          main.page6();
          break;
        case 7:
          main.page7();
          break;
        case 8:
          main.page8();
          break;
        case 9:
          main.page9();
          break;
        case 10:
          main.page10();
          break;
        case 11:
          main.page11();
          break;
        default:
          break;
      }
    }
    function getPage(id) {
      switch (id){
        case 1:
          return main.obj.page1Container;
          break;
        case 2:
          return main.obj.page2Container;
          break;
        case 3:
          return main.obj.page3Container;
          break;
        case 4:
          return main.obj.page4Container;
          break;
        case 5:
          return main.obj.page5Container;
          break;
        case 6:
          return main.obj.page6Container;
          break;
        case 7:
          return main.obj.page7Container;
          break;
        case 8:
          return main.obj.page8Container;
          break;
        case 9:
          return main.obj.page9Container;
          break;
        case 10:
          return main.obj.page10Container;
          break;
        case 11:
          return main.obj.page11Container;
          break;
        default:
          break;
      }
    }
  },
  addTxt:function(container, pic_data, waittime,gotime,num){
    var txtContainer = new createjs.Container().set({x:0,y:0});
    container.addChild(txtContainer);
    var pic_txt = pic_data;
    var spr_txt = new createjs.SpriteSheet(pic_txt);
    for(var i=0;i<num;i++){
      var txt = new createjs.Sprite(spr_txt).set({x:pic_txt.frames[i][0],y:pic_txt.frames[i][1],alpha:0});
      txt.gotoAndPlay("txt"+(i+1));
      txtContainer.addChild(txt);
      createjs.Tween.get(txt)
        .wait(waittime+gotime/2*i)
        .to({alpha:1},gotime)
    }
  },
  addUp:function(container){
    var upCon = new createjs.Container();
    container.addChild(upCon);
    var up1 = new createjs.Bitmap(main.obj.queue.getResult("up")).set({x:350,y:initHeight-25,alpha:0,scaleX:1,scaleY:1});
    var up2 = new createjs.Bitmap(main.obj.queue.getResult("up")).set({x:350,y:initHeight-35,alpha:0,scaleX:1,scaleY:1});
    var up3 = new createjs.Bitmap(main.obj.queue.getResult("up")).set({x:350,y:initHeight-45,alpha:0,scaleX:1,scaleY:1});
    upCon.addChild(up1,up2,up3);
    createjs.Tween.get(up3,{loop:true}).wait(800).to({alpha:1,y:initHeight-65},500).wait(1500);
    createjs.Tween.get(up2,{loop:true}).wait(800+500).to({alpha:1,y:initHeight-55},500).wait(1000);
    createjs.Tween.get(up1,{loop:true}).wait(800+1000).to({alpha:1,y:initHeight-45},500).wait(500);
  },
  page1:function(){
    main.obj.page1Container = new createjs.Container().set({x:0,y:0});
    stage.addChild(main.obj.page1Container);

    var p1_bg = new createjs.Bitmap(main.obj.queue.getResult("p1_bg"));
    main.obj.page1Container.addChild(p1_bg);


    var data_img= {
      images:[main.obj.queue.getResult("p1_img")],
      frames:[[218,1172,85,85],[464,1189,45,54],[143,828,464,107],[99,709,558,66],[45,372,686,296],[338,152,315,212]],
      animations : {open:[0],hand:[1],message:[2],title:[3],shan:[4],ren:[5]}
    };
    var spr_img= new createjs.SpriteSheet(data_img);
    var open = new createjs.Sprite(spr_img);open.gotoAndPlay("open");
    var hand = new createjs.Sprite(spr_img);hand.gotoAndPlay("hand");
    var message = new createjs.Sprite(spr_img);message.gotoAndPlay("message");
    var title = new createjs.Sprite(spr_img);title.gotoAndPlay("title");
    var shan = new createjs.Sprite(spr_img);shan.gotoAndPlay("shan");
    // var ren = new createjs.Sprite(spr_img);ren.gotoAndPlay("ren");
    open.set({x:data_img.frames[0][0]+data_img.frames[0][2]/2,y:data_img.frames[0][1]+data_img.frames[0][3]/2,regX:data_img.frames[0][2]/2,regY:data_img.frames[0][3]/2,alpha:1});
    hand.set({x:data_img.frames[1][0]+data_img.frames[1][2]/2,y:data_img.frames[1][1]+data_img.frames[1][3]/2,regX:data_img.frames[1][2]/2,regY:data_img.frames[1][3]/2,alpha:1});
    message.set({x:data_img.frames[2][0]+data_img.frames[2][2]/2,y:data_img.frames[2][1]+data_img.frames[2][3]/2+10,regX:data_img.frames[2][2]/2,regY:data_img.frames[2][3]/2,alpha:0});
    title.set({x:data_img.frames[3][0]+data_img.frames[3][2]/2,y:data_img.frames[3][1]+data_img.frames[3][3]/2,regX:data_img.frames[3][2]/2,regY:data_img.frames[3][3]/2,alpha:0});
    shan.set({x:data_img.frames[4][0]+data_img.frames[4][2]/2,y:data_img.frames[4][1]+data_img.frames[4][3]/2,regX:data_img.frames[4][2]/2,regY:data_img.frames[4][3]/2,alpha:1});

    main.obj.page1Container.addChild(open,hand,message,title,shan);

    var p_jian = new createjs.Bitmap(main.obj.queue.getResult("p_jian")).set({x:-315,y:167+100});

    var data_ren= {
      images:[main.obj.queue.getResult("p_xin")],
      frames:{width:315,height:212},
      animations : {stand:[0],run:[0,3,"run",0.3],run2:[4,7,"run3",0.3],run3:[7,13,"run3",0.3]}
    };
    var spr_ren= new createjs.SpriteSheet(data_ren);
    var ren = new createjs.Sprite(spr_ren);ren.gotoAndPlay("run");
    main.obj.page1Container.addChild(p_jian,ren);
    ren.set({x:338,y:152+100});
    createjs.Tween.get(p_jian).wait(1000).to({x:338},600,createjs.Ease.quadIn)
      .call(function () {
        ren.gotoAndPlay("run2");
      });

    createjs.Tween.get(hand,{loop:true}).to({x:250+45/2}).to({x:464+45/2},1000);
    createjs.Tween.get(title).wait(1000).to({scaleX:0,scaleY:0,alpha:1}).to({scaleX:1,scaleY:1},1000,createjs.Ease.bounceOut);
    createjs.Tween.get(shan,{loop:true}).to({alpha:0.3},100).to({alpha:1},100);
    // createjs.Tween.get(ren).wait(1600).to({alpha:1}).to({x:-data_img.frames[5][2]/2}).to({x:data_img.frames[5][0]+data_img.frames[5][2]/2},1000,createjs.Ease.bounceOut);
    createjs.Tween.get(message).wait(2000).call(function(){
      createjs.Sound.play("didi", {interrupt: createjs.Sound.INTERRUPT_NONE,  volume: 1});
    }).wait(500).to({y:data_img.frames[2][1]+data_img.frames[2][3]/2,alpha:1},200);

    var openX = 0,isMove = false,isEnd = false;
    open.addEventListener("mousedown",function(e){
      openX = e.stageX;
    });
    open.addEventListener("pressmove",function(e) {
      var tempX = e.stageX - openX;
      if((open.x+tempX)<=(218+85/2)){
        open.x = 218+85/2; return;
      }else if((open.x+tempX)>=(450+85/2)){
        open.x = 450+85/2;
        if(!isEnd){
          doMyPage(2,1);
          isEnd = true;
        }

        return;
      }else{
        open.x+=tempX;
      }
      openX = e.stageX;
      if(isMove) return;
      isMove = true;
      main.obj.page1Container.removeChild(hand);
    });
    open.addEventListener("pressup",function(e) {
      if(!isEnd){
        isMove = false;
        main.obj.page1Container.addChild(hand);
        open.x = 218+85/2;
      }

    });

  },
  page2:function(){

    main.obj.page2Container = new createjs.Container().set({x:0,y:0});
    stage.addChild(main.obj.page2Container);

    var data_bg= {
      images:[main.obj.queue.getResult("p2_bg")],
      frames:{width:750,height:1333},
      animations : {run:[0,1,"run",0.1],}
    };
    var spr_bg= new createjs.SpriteSheet(data_bg);
    var p2_bg = new createjs.Sprite(spr_bg);p2_bg.gotoAndPlay("run");
    main.obj.page2Container.addChild(p2_bg);

    var data_img= {
      images:[main.obj.queue.getResult("p2_img")],
      frames:[[283,72,66,219],[357,55,30,175],[402,88,30,453],[320,278,83,496],[285,311,27,765],[414,566,18,439],[380,781,22,289],[320,811,50,286],[282,1130,48,140],[348,1112,41,156],[395,1082,39,191],
        [111,131,109,171],[527,695,173,313],[531,646,35,33],[102,74,60,56]],
      animations : {txt1:[0],txt2:[1],txt3:[2],txt4:[3],txt5:[4],txt6:[5],txt7:[6],txt8:[7],txt9:[8],txt10:[9],txt11:[10],txt12:[11],txt13:[12],txt14:[13],txt15:[14],txt16:[15],txt17:[16],txt18:[17],txt19:[18],txt20:[19]}
    };

    var spr_img= new createjs.SpriteSheet(data_img);
    var ren1 = new createjs.Sprite(spr_img);ren1.gotoAndPlay("txt12");
    var ren2 = new createjs.Sprite(spr_img);ren2.gotoAndPlay("txt13");
    var xing1 = new createjs.Sprite(spr_img);xing1.gotoAndPlay("txt14");
    var xing2 = new createjs.Sprite(spr_img);xing2.gotoAndPlay("txt15");
    ren1.set({x:-data_img.frames[11][2]/2,y:data_img.frames[11][1]+data_img.frames[11][3]/2,regX:data_img.frames[11][2]/2,regY:data_img.frames[11][3]/2});
    ren2.set({x:750+data_img.frames[12][2]/2,y:data_img.frames[12][1]+data_img.frames[12][3]/2,regX:data_img.frames[12][2]/2,regY:data_img.frames[12][3]/2});
    xing1.set({x:data_img.frames[13][0]+data_img.frames[13][2]/2+3,y:data_img.frames[13][1]+data_img.frames[13][3]/2+3,regX:data_img.frames[13][2]/2,regY:data_img.frames[13][3]/2});
    xing2.set({x:data_img.frames[14][0]+data_img.frames[14][2]/2+5,y:data_img.frames[14][1]+data_img.frames[14][3]/2+5,regX:data_img.frames[14][2]/2,regY:data_img.frames[14][3]/2});
    main.obj.page2Container.addChild(ren1,ren2,xing1,xing2);
    createjs.Tween.get(xing1,{loop:true}).to({rotation:360},2000);
    createjs.Tween.get(xing2,{loop:true}).to({rotation:360},2000);
    createjs.Tween.get(ren1).wait(600).to({x:data_img.frames[11][0]+data_img.frames[11][2]/2},600);
    createjs.Tween.get(ren2).wait(600).to({x:data_img.frames[12][0]+data_img.frames[12][2]/2},600);

    var soundPosArr = [0,700,1480,3260,4200,10700,15200,17200,18200,19000,19600];

    var p_btn = new createjs.Bitmap(main.obj.queue.getResult("p_btn")).set({x:608,y:1228});
    main.obj.page2Container.addChild(p_btn);
    var isTiao = false;


    var timeout1 = setTimeout(function () {
      if(!isTiao){
        addTxt2(soundPosArr,data_img,1000,600,11);
      }
    },1600);

    function addTxt2(soundPosArr, pic_data, waittime,gotime,num){
      createjs.Sound.play("sound1", {interrupt: createjs.Sound.INTERRUPT_NONE,  volume: 1});
      var txtContainer = new createjs.Container().set({x:0,y:0});
      main.obj.page2Container.addChild(txtContainer);
      var pic_txt = pic_data;
      var spr_txt = new createjs.SpriteSheet(pic_txt);
      for(var i=0;i<num;i++){
        var txt = new createjs.Sprite(spr_img).set({x:data_img.frames[i][0]+data_img.frames[i][2]/2,y:data_img.frames[i][1]+data_img.frames[i][3]/2,regX:data_img.frames[i][2]/2,regY:data_img.frames[i][3]/2,alpha:0});
        txt.gotoAndPlay("txt"+(i+1));
        txtContainer.addChild(txt);

        if(i==0){
          createjs.Tween.get(txt).to({y:-data_img.frames[i][3]/2}).wait(soundPosArr[i]).to({y:data_img.frames[i][1]+data_img.frames[i][3]/2,alpha:1},gotime);
        }else if(i==2){
          txt.set({x:data_img.frames[i][0],y:data_img.frames[i][1],regX:0,regY:0,alpha:0,rotation:-90});
          createjs.Tween.get(txt).wait(soundPosArr[i]).to({rotation:0,alpha:1},gotime);
        }else if(i==3){
          createjs.Tween.get(txt).to({scaleX:2,scaleY:2}).wait(soundPosArr[i]).to({scaleX:1,scaleY:1,alpha:1},gotime,createjs.Ease.bounceOut)
            .wait(6000)
            .to({scaleX:1.5,scaleY:1.5},200)
            .to({scaleX:1,scaleY:1},gotime,createjs.Ease.bounceOut)
        }else if(i==4){
          createjs.Tween.get(txt).wait(soundPosArr[i]).to({rotation:360,alpha:1},gotime+1000,createjs.Ease.bounceOut);
        }else if(i==5){
          txt.x = data_img.frames[i][0]+data_img.frames[i][2]/2+100;
          createjs.Tween.get(txt).wait(soundPosArr[i]).to({x:data_img.frames[i][0]+data_img.frames[i][2]/2,alpha:1},gotime);
        }else{
          createjs.Tween.get(txt).to({scaleX:2,scaleY:2}).wait(soundPosArr[i]).to({scaleX:1,scaleY:1,alpha:1},gotime,createjs.Ease.bounceOut);
        }
      }
    }



    var timeout2 = setTimeout(function () {
      if(!isTiao){
        doMyPage(3,0);
      }
    },22000);

    p_btn.addEventListener("mousedown",function(e){
      isTiao = true;
      doMyPage(6,0);
      clearInterval(timeout1);
      clearInterval(timeout2);
    });


  },
  page3:function(){
    // createjs.Sound.stop();
    main.obj.page3Container = new createjs.Container().set({x:0,y:0});
    stage.addChild(main.obj.page3Container);

    var p3_bg = new createjs.Bitmap(main.obj.queue.getResult("p3_bg"));

    var data_img= {
      images:[main.obj.queue.getResult("p3_bg")],
      frames:[[0,0,750,1333],[0,1007,750,326]],
      animations : {p3_bg:[0],p3_bgb:[1]}
    };
    var spr_img= new createjs.SpriteSheet(data_img);
    var p3_bg = new createjs.Sprite(spr_img);p3_bg.gotoAndPlay("p3_bg");
    main.obj.page3Container.addChild(p3_bg);

    var p3_wdjr = new createjs.Bitmap(main.obj.queue.getResult("p3_wdjr")).set({x:290,y:24});
    main.obj.page3Container.addChild(p3_wdjr);

    var p3_bgt = new createjs.Bitmap(main.obj.queue.getResult("p3_bgt"));
    main.obj.page3Container.addChild(p3_bgt);
    var p3_bgb = new createjs.Sprite(spr_img);p3_bgb.gotoAndPlay("p3_bgb");p3_bgb.set({y:1007});
    main.obj.page3Container.addChild(p3_bgb);


    var p3_wdj = new createjs.Bitmap(main.obj.queue.getResult("p3_wdj"));
    main.obj.page3Container.addChild(p3_wdj);

    var s1Container = new createjs.Container().set({x:0,y:0});
    main.obj.page3Container.addChild(s1Container);
    var s1PosArr = [300,2000,4700,6000,9700];//14000
    var data_img1= {
      images:[main.obj.queue.getResult("p3_img1")],
      frames:[[309,1002,215,38],[311,1046,212,37],[267,1096,342,69],//title
        [137,342,295,49],[222,424,444,50],[127,505,364,50],[48,586,650,50],[201,669,296,49],//neirong
        [89,754,135,327],[556,753,113,247],//ren
        [38,1178,44,39]],//other
      animations : {img1:[0],img2:[1],img3:[2],img4:[3],img5:[4],img6:[5],img7:[6],img8:[7],img9:[8],img10:[9],img11:[10],img12:[11],img13:[12],img14:[13],img15:[14],img16:[15],img17:[16],img18:[17],img19:[18],img20:[19],img21:[20],img22:[21],img23:[22],img24:[23]}
    };
    var spr_img1= new createjs.SpriteSheet(data_img1);

    doSound1();

    var s2Container = new createjs.Container().set({x:0,y:0,alpha:0});
    main.obj.page3Container.addChild(s2Container);
    var s2PosArr = [500,1800,3000,5800,7600];//10000
    var data_img2= {
      images:[main.obj.queue.getResult("p3_img2")],
      frames:[[309,999,248,38],[311,1046,212,37],[281,1092,371,91],//title
        [136,340,296,50],[320,422,217,50],[110,504,522,50],[190,585,364,49],[200,666,296,50],//neirong
        [536,787,183,211],//ren[531,703,188,295]
        [95,229,60,51],[125,1217,88,89]],//other
      animations : {img1:[0],img2:[1],img3:[2],img4:[3],img5:[4],img6:[5],img7:[6],img8:[7],img9:[8],img10:[9],img11:[10],img12:[11],img13:[12],img14:[13],img15:[14],img16:[15],img17:[16],img18:[17],img19:[18],img20:[19],img21:[20],img22:[21],img23:[22],img24:[23]}
    };


    // createjs.Tween.get(s2Container).to({alpha:1},1000);
    // doSound2();

    var s3Container = new createjs.Container().set({x:0,y:0,alpha:0});
    main.obj.page3Container.addChild(s3Container);
    var s3PosArr = [300,2000,3000,5000,7000];//10500
    var data_img3= {
      images:[main.obj.queue.getResult("p3_img3")],
      frames:[[311,1004,289,38],[309,1048,215,36],[281,1090,406,74],//title
        [139,342,296,50],[325,424,179,49],[163,506,247,49],[106,588,492,49],[204,669,296,49],//neirong
        [534,693,171,310],//ren
        [126,1005,59,49],[211,836,37,37]],//other
      animations : {img1:[0],img2:[1],img3:[2],img4:[3],img5:[4],img6:[5],img7:[6],img8:[7],img9:[8],img10:[9],img11:[10],img12:[11],img13:[12],img14:[13],img15:[14],img16:[15],img17:[16],img18:[17],img19:[18],img20:[19],img21:[20],img22:[21],img23:[22],img24:[23]}
    };

    // createjs.Tween.get(s3Container).to({alpha:1},1000);
    // doSound3();

    var s4Container = new createjs.Container().set({x:0,y:0,alpha:0});
    main.obj.page3Container.addChild(s4Container);
    var s4PosArr = [300,2300,4000];//6000
    var data_img4= {
      images:[main.obj.queue.getResult("p3_img4")],
      frames:[[325,1048,248,37],[343,1093,213,37],[68,1142,617,56],//title
        [36,425,420,50],[245,506,419,50],[201,586,297,50],//neirong
        [496,754,239,251],//ren
        [122,302,59,48],[122,859,39,38],[188,1062,44,44]],//other
      animations : {img1:[0],img2:[1],img3:[2],img4:[3],img5:[4],img6:[5],img7:[6],img8:[7],img9:[8],img10:[9],img11:[10],img12:[11],img13:[12],img14:[13],img15:[14],img16:[15],img17:[16],img18:[17],img19:[18],img20:[19],img21:[20],img22:[21],img23:[22],img24:[23]}
    };

    // createjs.Tween.get(s4Container).to({alpha:1},1000);
    // doSound4();




    function doSound1() {
      setTimeout(function () {
        createjs.Sound.play("sound2", {interrupt: createjs.Sound.INTERRUPT_NONE,  volume: 1});
      },600);
      var data_img = data_img1;
      var spr_img = new createjs.SpriteSheet(data_img1);
      for(var i=0;i<data_img.frames.length;i++){
        if(i<=1){
          var img = new createjs.Sprite(spr_img).set({x:data_img.frames[i][0]+data_img.frames[i][2]/2,y:data_img.frames[i][1]+data_img.frames[i][3]/2,regX:data_img.frames[i][2]/2,regY:data_img.frames[i][3]/2,alpha:0});
          img.gotoAndPlay("img"+(i+1));
          createjs.Tween.get(img).wait(s1PosArr[s1PosArr.length-1]+400*i).to({scaleX:0,scaleY:0,alpha:1}).to({scaleX:1,scaleY:1},800,createjs.Ease.bounceOut);
        }else if(i==2){
          var img = new createjs.Sprite(spr_img).set({x:data_img.frames[i][0]+data_img.frames[i][2]/2,y:data_img.frames[i][1]+data_img.frames[i][3]/2,regX:data_img.frames[i][2]/2,regY:data_img.frames[i][3]/2,alpha:0});
          img.gotoAndPlay("img"+(i+1));
          createjs.Tween.get(img).wait(s1PosArr[s1PosArr.length-1]+400*i).to({scaleX:3,scaleY:3}).to({scaleX:1,scaleY:1,alpha:1},800,createjs.Ease.bounceOut);
        }else if(i>=3&&i<=7){
          var img = new createjs.Sprite(spr_img).set({x:750,y:data_img.frames[i][1]});
          img.gotoAndPlay("img"+(i+1));
          createjs.Tween.get(img).wait(s1PosArr[i-3]).to({x:-data_img.frames[i][2]},5000);
        }else if(i==8){
          var img = new createjs.Sprite(spr_img).set({x:-data_img.frames[i][2],y:data_img.frames[i][1],alpha:1});
          img.gotoAndPlay("img"+(i+1));
          createjs.Tween.get(img).wait(500).to({x:data_img.frames[i][0]},1000,createjs.Ease.bounceOut);
        }else if(i==9){
          var img = new createjs.Sprite(spr_img).set({x:750,y:data_img.frames[i][1]});
          img.gotoAndPlay("img"+(i+1));
          createjs.Tween.get(img).wait(2000).to({x:data_img.frames[i][0]},1000,createjs.Ease.bounceOut);
        }else if(i==10){
          var img = new createjs.Sprite(spr_img).set({x:data_img.frames[i][0],y:data_img.frames[i][1]});
          img.gotoAndPlay("img"+(i+1));
        }
        s1Container.addChild(img);
      }
      createjs.Tween.get(p3_wdjr).to({y:284},13500);
      createjs.Tween.get(s1Container)
        .wait(14000)
        .to({alpha:0},1000)
        .call(function () {
          createjs.Tween.get(s2Container)
            .to({alpha:1},1000);
          doSound2();
        })
    }

    function doSound2() {
      setTimeout(function () {
        createjs.Sound.play("sound3", {interrupt: createjs.Sound.INTERRUPT_NONE,  volume: 1});
      },600);
      var data_img = data_img2;
      var spr_img = new createjs.SpriteSheet(data_img2);
      for(var i=0;i<data_img.frames.length;i++){
        if(i<=1){
          var img = new createjs.Sprite(spr_img).set({x:data_img.frames[i][0]+data_img.frames[i][2]/2,y:data_img.frames[i][1]+data_img.frames[i][3]/2,regX:data_img.frames[i][2]/2,regY:data_img.frames[i][3]/2,alpha:0});
          img.gotoAndPlay("img"+(i+1));
          createjs.Tween.get(img).wait(600+s2PosArr[s2PosArr.length-1]+400*i).to({scaleX:0,scaleY:0,alpha:1}).to({scaleX:1,scaleY:1},800,createjs.Ease.bounceOut);
        }else if(i==2){
          var img = new createjs.Sprite(spr_img).set({x:data_img.frames[i][0]+data_img.frames[i][2]/2,y:data_img.frames[i][1]+data_img.frames[i][3]/2,regX:data_img.frames[i][2]/2,regY:data_img.frames[i][3]/2,alpha:0});
          img.gotoAndPlay("img"+(i+1));
          createjs.Tween.get(img).wait(600+s2PosArr[s2PosArr.length-1]+400*i).to({scaleX:3,scaleY:3}).to({scaleX:1,scaleY:1,alpha:1},800,createjs.Ease.bounceOut);
        }else if(i>=3&&i<=7){
          var img = new createjs.Sprite(spr_img).set({x:750,y:data_img.frames[i][1]});
          img.gotoAndPlay("img"+(i+1));
          createjs.Tween.get(img).wait(1000+s2PosArr[i-3]).to({x:-data_img.frames[i][2]},5000);
        }else if(i==8){
          var img = new createjs.Sprite(spr_img).set({x:-data_img.frames[i][2],y:data_img.frames[i][1],alpha:1});
          img.gotoAndPlay("img"+(i+1));

          var p_xinsui= main.getAni("p_xinsui",12,100,100,0.3);
          p_xinsui.set({x:531,y:703-20,alpha:0});p_xinsui.gotoAndPlay("stand");
          s2Container.addChild(p_xinsui);

          createjs.Tween.get(img).wait(2000).to({x:data_img.frames[i][0]},1000)
            .call(function () {
              createjs.Tween.get(p_xinsui).to({alpha:1},1000)
                .to({alpha:0},1000)
                .to({alpha:1},1000)
                .wait(1000)
                .call(function () {
                  p_xinsui.gotoAndPlay("run2end");
                })
            })

        }else if(i>8){
          var img = new createjs.Sprite(spr_img).set({x:data_img.frames[i][0],y:data_img.frames[i][1]});
          img.gotoAndPlay("img"+(i+1));
        }
        s2Container.addChild(img);
      }



      createjs.Tween.get(p3_wdjr).to({y:524},9500);
      setTimeout(function () {
        createjs.Tween.get(s2Container)
          .to({alpha:0},1000)
          .call(function () {
            doSound3();
            createjs.Tween.get(s3Container)
              .to({alpha:1},1000)
          })
      },11000)
    }

    function doSound3() {
      setTimeout(function () {
        createjs.Sound.play("sound4", {interrupt: createjs.Sound.INTERRUPT_NONE,  volume: 1});
      },600);
      var data_img = data_img3;
      var spr_img = new createjs.SpriteSheet(data_img3);
      for(var i=0;i<data_img.frames.length;i++){
        if(i<=1){
          var img = new createjs.Sprite(spr_img).set({x:data_img.frames[i][0]+data_img.frames[i][2]/2,y:data_img.frames[i][1]+data_img.frames[i][3]/2,regX:data_img.frames[i][2]/2,regY:data_img.frames[i][3]/2,alpha:0});
          img.gotoAndPlay("img"+(i+1));
          createjs.Tween.get(img).wait(600+s3PosArr[s3PosArr.length-1]+400*i).to({scaleX:0,scaleY:0,alpha:1}).to({scaleX:1,scaleY:1},800,createjs.Ease.bounceOut);
        }else if(i==2){
          var img = new createjs.Sprite(spr_img).set({x:data_img.frames[i][0]+data_img.frames[i][2]/2,y:data_img.frames[i][1]+data_img.frames[i][3]/2,regX:data_img.frames[i][2]/2,regY:data_img.frames[i][3]/2,alpha:0});
          img.gotoAndPlay("img"+(i+1));
          createjs.Tween.get(img).wait(600+s3PosArr[s3PosArr.length-1]+400*i).to({scaleX:3,scaleY:3}).to({scaleX:1,scaleY:1,alpha:1},800,createjs.Ease.bounceOut);
        }else if(i>=3&&i<=7){
          var img = new createjs.Sprite(spr_img).set({x:750,y:data_img.frames[i][1]});
          img.gotoAndPlay("img"+(i+1));
          createjs.Tween.get(img).wait(1000+s3PosArr[i-3]).to({x:-data_img.frames[i][2]},5000);
        }else if(i==8){
          var img = new createjs.Sprite(spr_img).set({x:-data_img.frames[i][2],y:data_img.frames[i][1],alpha:1});
          img.gotoAndPlay("img"+(i+1));
          createjs.Tween.get(img).wait(2000).to({x:data_img.frames[i][0]},1000);
        }else if(i>8){
          var img = new createjs.Sprite(spr_img).set({x:data_img.frames[i][0],y:data_img.frames[i][1]});
          img.gotoAndPlay("img"+(i+1));
        }
        s3Container.addChild(img);
      }

      createjs.Tween.get(p3_wdjr).to({y:764},10000);
      setTimeout(function () {
        createjs.Tween.get(s3Container)
          .to({alpha:0},1000)
          .call(function () {
            doSound4();
            createjs.Tween.get(s4Container)
              .to({alpha:1},1000)
          })
      },10500)
    }

    function doSound4() {
      setTimeout(function () {
        createjs.Sound.play("sound5", {interrupt: createjs.Sound.INTERRUPT_NONE,  volume: 1});
      },600);
      var data_img = data_img4;
      var spr_img = new createjs.SpriteSheet(data_img4);
      for(var i=0;i<data_img.frames.length;i++){
        if(i<=1){
          var img = new createjs.Sprite(spr_img).set({x:data_img.frames[i][0]+data_img.frames[i][2]/2,y:data_img.frames[i][1]+data_img.frames[i][3]/2,regX:data_img.frames[i][2]/2,regY:data_img.frames[i][3]/2,alpha:0});
          img.gotoAndPlay("img"+(i+1));
          createjs.Tween.get(img).wait(600+s4PosArr[s4PosArr.length-1]+400*i).to({scaleX:0,scaleY:0,alpha:1}).to({scaleX:1,scaleY:1},800,createjs.Ease.bounceOut);
        }else if(i==2){
          var img = new createjs.Sprite(spr_img).set({x:data_img.frames[i][0]+data_img.frames[i][2]/2,y:data_img.frames[i][1]+data_img.frames[i][3]/2,regX:data_img.frames[i][2]/2,regY:data_img.frames[i][3]/2,alpha:0});
          img.gotoAndPlay("img"+(i+1));
          createjs.Tween.get(img).wait(600+s4PosArr[s4PosArr.length-1]+400*i).to({scaleX:3,scaleY:3}).to({scaleX:1,scaleY:1,alpha:1},800,createjs.Ease.bounceOut);
        }else if(i>=3&&i<=5){
          var img = new createjs.Sprite(spr_img).set({x:750,y:data_img.frames[i][1]});
          img.gotoAndPlay("img"+(i+1));
          createjs.Tween.get(img).wait(s1PosArr[i-3]).to({x:-data_img.frames[i][2]},5000);
        }else if(i==6){
          var img = new createjs.Sprite(spr_img).set({x:-data_img.frames[i][2],y:data_img.frames[i][1],alpha:1});
          img.gotoAndPlay("img"+(i+1));
          createjs.Tween.get(img).wait(2000).to({x:data_img.frames[i][0]},1000);
        }else if(i>6){
          var img = new createjs.Sprite(spr_img).set({x:data_img.frames[i][0],y:data_img.frames[i][1]});
          img.gotoAndPlay("img"+(i+1));
        }
        s4Container.addChild(img);
      }
      createjs.Tween.get(p3_wdjr).to({y:1000},5500);
      setTimeout(function () {
        createjs.Tween.get(s4Container)
          .to({alpha:0},1000);
        doMyPage(4,0);
      },8000)

    }

  },
  page4:function(){
    main.obj.page4Container = new createjs.Container().set({x:0,y:0});
    stage.addChild(main.obj.page4Container);

    var shape_bg = new createjs.Shape();
    shape_bg.graphics.beginFill("#fff").drawRect(0, 0, 750, initHeight);
    main.obj.page4Container.addChild(shape_bg);

    var p3_wdjr = new createjs.Bitmap(main.obj.queue.getResult("p3_wdjr")).set({x:293,y:1006});
    main.obj.page4Container.addChild(p3_wdjr);

    var p4_bg = new createjs.Bitmap(main.obj.queue.getResult("p4_bg"));
    main.obj.page4Container.addChild(p4_bg);

    // var p4_img = new createjs.Bitmap(main.obj.queue.getResult("p4_img"));
    // main.obj.page4Container.addChild(p4_img);

    var zhiwen;

    var data_img= {
      images:[main.obj.queue.getResult("p4_img")],
      frames:[[127,806,217,151],[526,694,159,81],[538,467,56,48],[515,76,199,102],
        [138,334,66,114],[100,1038,548,44],[316,1139,121,110],
        [243,145,267,169]],
      animations : {img1:[0],img2:[1],img3:[2],img4:[3],img5:[4],img6:[5],img7:[6],ren:[7]}
    };
    var spr_img= new createjs.SpriteSheet(data_img);
    // var p4_ren = new createjs.Sprite(spr_img);p4_ren.gotoAndPlay("ren");p4_ren.set({x:243+267/2,y:1418,regX:267/2,regY:169/2});
    // main.obj.page4Container.addChild(p4_ren);

    var spr_img = new createjs.SpriteSheet(data_img);
    for(var i=0;i<data_img.frames.length-1;i++){
      var img = new createjs.Sprite(spr_img).set({x:data_img.frames[i][0]+data_img.frames[i][2]/2,y:data_img.frames[i][1]+data_img.frames[i][3]/2,regX:data_img.frames[i][2]/2,regY:data_img.frames[i][3]/2,alpha:0});
      img.gotoAndPlay("img"+(i+1));
      if(i<=3){
        // img.alpha = 1;
      }else if(i==4){//[21,334,263,401]
        createjs.Tween.get(img).to({scaleY:0,alpha:1}).wait(1000).to({scaleY:1},1000,createjs.Ease.bounceOut);
      }else if(i==5){
        createjs.Tween.get(img).wait(14000).to({scaleX:0,scaleY:0,alpha:1}).to({scaleX:1,scaleY:1},1000,createjs.Ease.bounceOut);
      }else if(i==6){
        zhiwen = img;
      }
      main.obj.page4Container.addChild(img);
    }

    createjs.Sound.play("sound6", {interrupt: createjs.Sound.INTERRUPT_NONE, volume: 1});
    createjs.Tween.get(p3_wdjr,{loop:true}).to({y:986},100).to({y:1006},100);

    //-----------------------------------------------
    var p_up= main.getAni("p_up",8,250,200,0.3);
    p_up.set({x:580,y:initHeight});p_up.gotoAndPlay("run");
    main.obj.page4Container.addChild(p_up);
    createjs.Tween.get(p_up,{loop:true}).to({x:-200,y:100},3000);

    var p_love = main.getAni("p_love",8,250,120,0.3);
    p_love.set({x:140,y:initHeight});p_love.gotoAndPlay("run");
    main.obj.page4Container.addChild(p_love);
    createjs.Tween.get(p_love,{loop:true}).to({x:551,y:-120},5000);

    var p_love2 = p_love.clone();
    p_love2.set({x:360,y:initHeight});
    main.obj.page4Container.addChild(p_love2);
    createjs.Tween.get(p_love2,{loop:true}).to({x:750,y:initHeight/2},2000);

    var p4_ren= main.getAni("p_ren",10,300,250,0.3);
    p4_ren.set({x:243+300/2,y:initHeight+250/2,regX:300/2,regY:250/2});p4_ren.gotoAndPlay("run");
    main.obj.page4Container.addChild(p4_ren);

    //-----------------------------------------------

    setTimeout(function () {
      createjs.Tween.get(p3_wdjr,{override:true}).to({y:1006},100);
      createjs.Sound.stop();
      createjs.Sound.play("ILoveYou", {interrupt: createjs.Sound.INTERRUPT_NONE, loop: -1,  volume: 1});

      var text = new createjs.Text("狂点指纹助力", "20px Arial", "#000");
      text.set({x:315,y:initHeight-90});
      createjs.Tween.get(text,{loop:true,override:true}).to({alpha:0.6},1000).to({alpha:1},1000);
      main.obj.page4Container.addChild(text);

      zhiwen.alpha = 1;
      createjs.Tween.get(zhiwen).to({alpha:1},600)
        .call(function () {
          createjs.Tween.get(zhiwen,{loop:true,override:true})
            .to({scaleX:0.8,scaleY:0.8,alpha:0.8},1000)
            .to({scaleX:1,scaleY:1,alpha:1},1000);
        });


      createjs.Tween.get(p4_ren).to({y:926},1000)
        .call(function () {
          zhiwen.addEventListener("mousedown",function(e){
            if(p3_wdjr.y<=30){
              doMyPage(5,0);
            }
            p3_wdjr.y -=(1006-30)/50;
            p4_ren.y -=(926-116)/50;

          });
        })
    },14000);

    var s6PosArr = [1000,3700,5000,6800,7600,10000,11300,12700];

    var talkArr = [[22,448],[140,491],[30,516],[38,553],[42,559],[60,612],[40,647],[21,685,263,50]];

    var data_txt= {
      images:[main.obj.queue.getResult("p4_txt")],
      frames:[[0,0,252,63],[0,63,128,40],[0,112,197,48],[0,160,100,40],[252,0,230,70],[252,70,130,42],[252,113,208,47],[219,160,263,50]],
      animations : {txt1:[0],txt2:[1],txt3:[2],txt4:[3],txt5:[4],txt6:[5],txt7:[6],txt8:[7]}
    };

    var sPosArr = [200,3200,4300,5600,6400,9000,10000,11000];
    doSound();
    function doSound() {
      var data_img = data_txt;
      var spr_img = new createjs.SpriteSheet(data_txt);
      for(var i=0;i<data_img.frames.length;i++){
        var img = new createjs.Sprite(spr_img).set({x:talkArr[i][0]+data_img.frames[i][2]/2,y:talkArr[i][1]+data_img.frames[i][3]/2,regX:data_img.frames[i][2]/2,regY:data_img.frames[i][3]/2,alpha:0});
        img.gotoAndPlay("txt"+(i+1));
        if(i==0){
          createjs.Tween.get(img).wait(sPosArr[i]).to({scaleX:0,scaleY:0}).to({scaleX:1,scaleY:1,alpha:1},800,createjs.Ease.bounceOut);
        }else if(i==2||i==4){
          createjs.Tween.get(img).wait(sPosArr[i]).to({scaleX:3,scaleY:3}).to({scaleX:1,scaleY:1,alpha:1},800,createjs.Ease.bounceOut);
        }else if(i==1){
          img.set({x:talkArr[i][0]+data_img.frames[i][2]/2+100});
          createjs.Tween.get(img).wait(sPosArr[i]).to({x:talkArr[i][0]+data_img.frames[i][2]/2,alpha:1},800,createjs.Ease.bounceOut);
        }else if(i==3){
          img.set({x:talkArr[i][0]+data_img.frames[i][2]/2-100});
          createjs.Tween.get(img).wait(sPosArr[i]).to({x:talkArr[i][0]+data_img.frames[i][2]/2,alpha:1},800,createjs.Ease.bounceOut);
        }else if(i>4){
          img.set({y:talkArr[i][1]+data_img.frames[i][3]/2+100});
          createjs.Tween.get(img).wait(sPosArr[i]).to({y:talkArr[i][1]+data_img.frames[i][3]/2,alpha:1},800,createjs.Ease.bounceOut);
        }
        main.obj.page4Container.addChild(img);
      }


    }

  },
  page5:function(){
    $("#username").hide();
    $("#address").hide();

    main.obj.page5Container = new createjs.Container().set({x:0,y:0});
    stage.addChild(main.obj.page5Container);

    var p5_bg = new createjs.Bitmap(main.obj.queue.getResult("p5_bg"));
    main.obj.page5Container.addChild(p5_bg);


    var data_img= {
      images:[main.obj.queue.getResult("p5_img")],
      frames:[[72,228,670,106],[159,938,433,264],[53,1209,93,124],[35,433,61,51],[676,377,29,29],[321,1254,34,34],[212,1208,327,86],[641,1042,34,34]],
      animations : {img1:[0],img2:[1],img3:[2],img4:[3],img5:[4],img6:[5],img7:[6],img8:[7],img9:[8],img10:[9]}
    };
    var spr_img= new createjs.SpriteSheet(data_img);
    var p1_img = new createjs.Sprite(spr_img);
    p1_img.gotoAndPlay("run");


    for(var i=0;i<data_img.frames.length;i++){
      if(i==0){
        var img = new createjs.Sprite(spr_img).set({x:750,y:data_img.frames[i][1],alpha:1});
        img.gotoAndPlay("img"+(i+1));

        var img2 = img.clone();
        main.obj.page5Container.addChild(img2);
        createjs.Tween.get(img,{loop:true}).to({x:-670},3000);
        createjs.Tween.get(img2).wait(1500)
          .call(function () {
            createjs.Tween.get(img2,{loop:true,override:true}).to({x:-670},3000);
          })

      }else if(i==1){
        var img = new createjs.Sprite(spr_img).set({x:data_img.frames[i][0]+data_img.frames[i][2]/2,y:data_img.frames[i][1]+data_img.frames[i][3]/2,regX:data_img.frames[i][2]/2,regY:data_img.frames[i][3]/2,alpha:1});
        img.gotoAndPlay("img"+(i+1));
      }else{
        var img = new createjs.Sprite(spr_img).set({x:data_img.frames[i][0]+data_img.frames[i][2]/2,y:data_img.frames[i][1]+data_img.frames[i][3]/2,regX:data_img.frames[i][2]/2,regY:data_img.frames[i][3]/2,alpha:1});
        img.gotoAndPlay("img"+(i+1));
        if(i==6){
          img.addEventListener("mousedown",function(e){
            doMyPage(6,0);
          });
        }

      }
      main.obj.page5Container.addChild(img);
    }

    var p_shan= main.getAni("p_shan",13,500,300,0.3);
    p_shan.set({x:124,y:25});p_shan.gotoAndPlay("run");
    main.obj.page5Container.addChild(p_shan);

    var p5_imgs= main.getAni("p5_imgs",5,647,644,0.1);
    p5_imgs.set({x:53,y:317});p5_imgs.gotoAndPlay("run");
    main.obj.page5Container.addChild(p5_imgs);

    var love= main.getAni("p5_love",9,433,274,0.3);
    love.set({x:580,y:initHeight});love.gotoAndPlay("img1");
    var love2 = love.clone();
    var love3 = love.clone();
    main.obj.page5Container.addChild(love,love2,love3);
    createjs.Tween.get(love,{loop:true})
      .wait(150)
      .call(function () {
        var thisX = parseInt(Math.random()*((650)-(100)+1)+(100),10);
        var thisY = parseInt(Math.random()*((1085)-(100)+1)+(100),10);
        var scale = parseInt(Math.random()*((10)-(5)+1)+(5),10)/10;
        var thisR = parseInt(Math.random()*((360)-(0)+1)+(0),10);
        var thisNum = parseInt(Math.random()*((9)-(1)+1)+(1),10);
        love2.set({x:thisX,y:thisY,rotation:thisR,scaleX:scale,scaleY:scale});
        love2.gotoAndPlay("img"+thisNum);
      })
      .wait(150)
      .call(function () {
        var thisX = parseInt(Math.random()*((650)-(100)+1)+(100),10);
        var thisY = parseInt(Math.random()*((1085)-(100)+1)+(100),10);
        var scale = parseInt(Math.random()*((10)-(5)+1)+(5),10)/10;
        var thisR = parseInt(Math.random()*((360)-(0)+1)+(0),10);
        love.set({x:thisX,y:thisY,rotation:thisR,scaleX:scale,scaleY:scale});
        var thisNum = parseInt(Math.random()*((9)-(1)+1)+(1),10);
        love.gotoAndPlay("img"+thisNum);
      })
      .wait(150)
      .call(function () {
        var thisX = parseInt(Math.random()*((650)-(100)+1)+(100),10);
        var thisY = parseInt(Math.random()*((1085)-(100)+1)+(100),10);
        var scale = parseInt(Math.random()*((10)-(5)+1)+(5),10)/10;
        var thisR = parseInt(Math.random()*((360)-(0)+1)+(0),10);
        love3.set({x:thisX,y:thisY,rotation:thisR,scaleX:scale,scaleY:scale});
        var thisNum = parseInt(Math.random()*((9)-(1)+1)+(1),10);
        love3.gotoAndPlay("img"+thisNum);
      });

  },
  page6:function(){
    createjs.Sound.stop();
    createjs.Sound.play("v_bgm", {interrupt: createjs.Sound.INTERRUPT_NONE, volume: 0.2});
    createjs.Sound.play("sound7", {interrupt: createjs.Sound.INTERRUPT_NONE, volume: 1});
    main.doSlide = false;
    main.obj.page6Container = new createjs.Container().set({x:0,y:0});
    stage.addChild(main.obj.page6Container);

    var p6_bg = new createjs.Bitmap(main.obj.queue.getResult("p6_bg"));
    main.obj.page6Container.addChild(p6_bg);

    // var p6_img = new createjs.Bitmap(main.obj.queue.getResult("p6_img"));
    // main.obj.page6Container.addChild(p6_img);
    var data_img= {
      images:[main.obj.queue.getResult("p6_img")],
      frames:[[99,196,560,89],[174,849,370,458]],
      animations : {img1:[0],img2:[1]}
    };
    var spr_img= new createjs.SpriteSheet(data_img);

    for(var i=0;i<data_img.frames.length;i++){
      var img = new createjs.Sprite(spr_img).set({x:data_img.frames[i][0]+data_img.frames[i][2]/2,y:data_img.frames[i][1]+data_img.frames[i][3]/2,regX:data_img.frames[i][2]/2,regY:data_img.frames[i][3]/2,alpha:0});
      img.gotoAndPlay("img"+(i+1));
      if(i==0){
        img.alpha = 1;
        // img.y = data_img.frames[i][1]+data_img.frames[i][3]/2-50;
        // createjs.Tween.get(img).to({y:data_img.frames[i][1]+data_img.frames[i][3]/2,alpha:1},1000);
        createjs.Tween.get(img,{loop:true,override:true})
          .to({scaleX:0.9,scaleY:0.9},300)
          .to({scaleX:1,scaleY:1},300)
      }else if(i==1){
        img.alpha = 1;
        createjs.Tween.get(img,{loop:true,override:true})
          .to({x:data_img.frames[i][0]+data_img.frames[i][2]/2+20},200)
          .to({x:data_img.frames[i][0]+data_img.frames[i][2]/2},200)
        img.addEventListener("click",function(e){
          var username = $("#username").val();
          var address = $("#address").val();

          if(username==""||username==null){
            doTips("请选择你想表白的对象");
          }else if(username.length>4){
            doTips("你想表白的对象的名字过长");
          }else if(address=="0"){
            doTips("请选择你想表白的坐标");
          }else{
            $.post("http://wx.csc-ad.cn/chongqin/love_save",{"username":username,"address":address},function(data){

            },"json");
            doMyPage(7,0);
          }

        });
      }
      main.obj.page6Container.addChild(img);
    }

    setTimeout(function () {
      $("#username").show();
      $("#address").show();
    },600);
    setTimeout(function () {
      main.doSlide = false;
    },700);


  },
  page7:function(){
    createjs.Sound.stop();
    createjs.Sound.play("v_bgm", {interrupt: createjs.Sound.INTERRUPT_NONE, volume: 0.2});
    $("#username").hide();
    $("#address").hide();
    main.obj.page7Container = new createjs.Container().set({x:0,y:0});
    stage.addChild(main.obj.page7Container);

    var shape_bg = new createjs.Shape();
    shape_bg.graphics.beginFill("#e50012").drawRect(0, 0, 750, initHeight);//e50012
    main.obj.page7Container.addChild(shape_bg);



    var data_img= {
      images:[main.obj.queue.getResult("p7_img")],
      frames:[[490,51,220,105],[136,926,480,142]],
      animations : {img1:[0],img2:[1]}
    };
    var spr_img= new createjs.SpriteSheet(data_img);
    for(var i=0;i<data_img.frames.length;i++){
      var img = new createjs.Sprite(spr_img).set({x:data_img.frames[i][0]+data_img.frames[i][2]/2,y:data_img.frames[i][1]+data_img.frames[i][3]/2,regX:data_img.frames[i][2]/2,regY:data_img.frames[i][3]/2,alpha:0});
      img.gotoAndPlay("img"+(i+1));
      if(i==0){
        img.alpha = 1;
        createjs.Tween.get(img,{loop:true,override:true})
          .to({scaleX:0.9,scaleY:0.9},300)
          .to({scaleX:1,scaleY:1},300)
      }else if(i==1){
        img.alpha = 1;
      }
      main.obj.page7Container.addChild(img);
    }

    main.makePic();

  },
  makePic:function () {
    canvas2 = document.createElement('canvas');
    canvas2.width = 982/5*3;
    canvas2.height = 983/5*3;
    canvas2.style.backgroundColor="#fff";
    canvas2.style.position="absolute";
    canvas2.style.zIndex = -1;
    canvas2.style.fontWeight ="bolder";
    canvas2.style.transform = 'scale(0.001,0.001)';
    document.body.appendChild(canvas2);

    canvas2.style.width = '682px';
    canvas2.style.height =  '684px';

    stage2 = new createjs.Stage(canvas2);
    createjs.Touch.enable(stage2);
    stage2.autoClear = true;
    createjs.Ticker.setFPS(30);
    createjs.Ticker.addEventListener("tick", stage2);

    main.obj.page8Container = new createjs.Container().set({x:0,y:0,scaleX:3/5,scaleY:3/5});
    stage2.addChild(main.obj.page8Container);


    var pageid = $("#address").val();

    var p7_bg = new createjs.Bitmap(main.obj.queue.getResult("p7_"+pageid));
    main.obj.page8Container.addChild(p7_bg);

    var str = $("#username").val();
    var len = str.length;
    var str2 = "";
    for(var i=0;i<str.length;i++){
      str2+=str.slice(i,i+1)+"\n";
    }

    var txtArr = [0,
      [32,602,(285-(len-3)*32),str2,0],
      [48,(678-(len-3)*24),307,str,0],
      [48,408-(len-3)*36,247-(len-3)*12,str,22],
      [54,(396-(len-3)*27),151,str,0],
      [42,(604-(len-3)*21),256,str,0],
      [54,(400-(len-3)*27),272,str,-8],
      [34,(490-(len-3)*17),245,str,0],
      [54,(381-(len-3)*27),306,str,0]];

    var text = new createjs.Text(txtArr[pageid][3], txtArr[pageid][0]+"px SimHei ", "#ea0d1f");
    text.lineHeight = 34;
    // text.fontWeight = 'bolder';
    // text.set({scaleX:2,scaleY:2});
    text.skewY = txtArr[pageid][4];
    text.set({x:txtArr[pageid][1],y:txtArr[pageid][2]});

    main.obj.page8Container.addChild(text);

    setTimeout(function () {
      $('#shareImg').attr("src", canvas2.toDataURL("image/png"));
      $('#shareImg').show();
    },200);


  },
  getAni:function (img,num,w,h,s) {
    var data_img= {
      images:[main.obj.queue.getResult(img)],
      frames:{width:w,height:h},
      animations : {stand:[0],run:[0,num-1,"run",s],run2end:[0,num-1,"end",s],end:[num-1],img1:[0],img2:[1],img3:[2],img4:[3],img5:[4],img6:[5],img7:[6],img8:[7],img9:[8]}
    };
    var spr_img= new createjs.SpriteSheet(data_img);
    return new createjs.Sprite(spr_img);

  }

};


Array.prototype.delOne=function(o){
  for(var i=0;i<=this.length-1;i++){
    if(this[i].id == o.id){
      this.splice(i,1);
    }
  }
};

var model = 1;//1 保持宽高比例显示完整   2 保持宽高比例部分显示   3 保持全屏允许拉伸  4 定位显示
function resize(){
  var stageWidth =  document.documentElement.clientWidth;
  var stageHeight = document.documentElement.clientHeight;
  var username = document.getElementById("username");
  var address = document.getElementById("address");
  var shareImg = document.getElementById("shareImg");
  if((stageWidth/stageHeight) > (initWidth/initHeight))
  {
    if(model==1){
      var cw = initWidth*stageHeight/initHeight;
      var ch = stageHeight;
      var cl = (stageWidth - initWidth*stageHeight/initHeight)/2;
      var ct = 0;
    }else if(model==2){
      var cw = stageWidth;
      var ch = initHeight*stageWidth/initWidth;
      var cl = 0;
      var ct = (stageHeight-ch)/2;
    }else if(model==3){
      var cw = stageWidth;
      var ch = stageHeight;
      var cl = 0;
      var ct = 0;
    }
  }else{
    if(model==1){
      var cw = stageWidth;
      var ch = initHeight*stageWidth/initWidth;
      var cl = 0;
      var ct = (stageHeight - initHeight*stageWidth/initWidth)/2;
    }else if(model==2){
      var cw = initWidth*stageHeight/initHeight;
      var ch = stageHeight;
      var cl = (stageWidth-cw)/2;
      var ct = 0;
    }else if(model==3){
      var cw = stageWidth;
      var ch = stageHeight;
      var cl = 0;
      var ct = 0;
    }
  }
  canvas.style.width = cw+ 'px';
  canvas.style.height = ch+ 'px';
  canvas.style.left = cl + 'px';
  canvas.style.top = ct + 'px';

  // addDiv(username,cw,ch,cl,ct,[356,359,189,23]);
  // addDiv(address,cw,ch,cl,ct,[356,407,189,23]);
  addDiv(username,cw,ch,cl,ct,[335+10,363,290,55]);
  addDiv(address,cw,ch,cl,ct,[335+10,433,290,55]);
  addDiv(shareImg,cw,ch,cl,ct,[34,190,682,684]);



};

function addDiv(obj,w,h,l,t,arr) {
  obj.style.width = w*arr[2]/initWidth+ 'px';
  obj.style.height = (h*arr[3]/initHeight)+ 'px';
  obj.style.left =( l +  w*arr[0]/initWidth)+'px';
  obj.style.top = (t+h*arr[1]/initHeight) + 'px';
  obj.style.fontSize = 30*w/750+'px';
}


function getShareInfo(){
  var url = window.location.href;
  $.post("http://wx.csc-ad.cn/tools/WxJsSdk.php",{"url":url},function(data){
    wx.config({
      debug: false,
      appId:data.appId,
      timestamp:data.timestamp,
      nonceStr:data.nonceStr,
      signature:data.signature,
      jsApiList: [
        'checkJsApi',
        'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'onMenuShareQQ',
        'onMenuShareWeibo',
        'hideOptionMenu'
      ]
    });
  },"json");
}

wx.ready(function () {
  playBGM();
  wx.onMenuShareAppMessage({
    title: wxInfo.title,
    desc: wxInfo.desc,
    link: window.location.href,
    imgUrl: wxInfo.imgUrl,
    success: function () {
      $.post("http://wx.csc-ad.cn/?s=index/shareCount",{"name":wxInfo.appName,"count":"onMenuShareAppMessage"},function(data){})
    }
  });
  wx.onMenuShareTimeline({
    title: wxInfo.title,
    link: window.location.href,
    imgUrl: wxInfo.imgUrl,
    success: function () {
      $.post("http://wx.csc-ad.cn/?s=index/shareCount",{"name":wxInfo.appName,"count":"onMenuShareTimeline"},function(data){})
    }
  });
});
